class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int minans = prices[0];
        int ans = 0;
        for(int i = 1; i < prices.size(); i ++)
        {   
            ans = max(prices[i] - minans,ans);
            minans = min(prices[i],minans);
        }

        return ans;
    }
};